package org.groupg.mockdatabyspring.morkdata.model.DBInfo;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.groupg.mockdatabyspring.morkdata.model.enums.LinkType;

import java.io.Serializable;
import java.util.List;

/**
 * 两个字段是相同数据的关系
 */
@Getter
@Setter
public class ColumnLink implements Serializable {

    /**
     * 左面的字段
     */
    private List<DBColumnInfo> leftColumn;

    /**
     * 右面的字段
     */
    private DBColumnInfo rightColumn;

    /**
     * 默认的相同关系
     */
    private String linkType= LinkType.SAME;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        ColumnLink that = (ColumnLink) o;

        return new EqualsBuilder().append(getLeftColumn(), that.getLeftColumn()).append(getRightColumn(), that.getRightColumn()).append(getLinkType(), that.getLinkType()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(getLeftColumn()).append(getRightColumn()).append(getLinkType()).toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("leftColumn", leftColumn)
                .append("rightColumn", rightColumn)
                .append("linkType", linkType)
                .toString();
    }
}
